<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Category extends MX_Controller {


	function __construct()
	{
		parent::__construct();
		$this->template->set_layout('listing');
		$data['Page'] = "LISTING";

		$this->load->model('category/category_model');
		$this->load->model('location/location_model');
		
		
	}
	
	
	
	
	public function all()
	{
		$this->template->set_layout('static');
		$data['category'] = $this->category_model->getCetegory(0,9999999);
		
		$data['site_title'] = $this->settings_model->siteInfo('web_title');
		$this->template->set_breadcrumb('Home', '/')
		//->set_breadcrumb('Category','')
		->set_breadcrumb('Category All','')
		;
		
		$this->template->set_partial('nav_bar','header/nav_bar');
		$this->template->set_partial('header_search','header/header_search');
		$this->template->build('category_all',$data);
	}	
	
	
	function autocomplete(){
			
		$search = $_GET['term'];
	
		$query = $this->db->query("SELECT id,name FROM `category_tree` WHERE `name` LIKE '%$search%' and id!=0 ORDER BY name ASC limit 15") or die('Something went wrong');
		$result = $query->result();
	
		/*
		 $json = '[';
		$first = true;
		foreach($query->result() as $row):
	
		if (!$first) {
		$json .=  ',';
		} else { $first = false;
		}
	
		$json .= '{"value":"'.$row->id.'","label":"'.htmlentities(stripslashes($row->name)).'"}';
	
		endforeach;
		$json .= ']';
		//echo $json;
	
		*/
	
		$row_set = array();
	
		foreach ($result as $row1){
			$row = array(
					'label'	=> stripslashes($row1->name),
					'value'	=> 	(int)$row1->id
			);
			$row_set[] = $row;//build an array
		}
	
		echo json_encode($row_set);//format the array into json data
	
	
	
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
